package com.sabo.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.logging.Logger;

@Component
public class CustomGlobalFilter implements GlobalFilter, Ordered {

    Logger log = Logger.getLogger(this.getClass().getName());

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("-------CustomGlobalFilter--------");
        //拦截住不放行
//        ServerHttpResponse response = exchange.getResponse();
//        response.setStatusCode(HttpStatus.BAD_REQUEST);
//        return response.setComplete();
        //通过
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 3;
    }

}
